package cn.ichiva.common.web;

/**
 * 返回统一数据结构
 * @author game group
 */
public class R<T> {

    /**
     * 成功数据
     */
    private T data;

    /**
     * 状态码 0正常，大于0非正常
     */
    private Integer code = 0;

    /**
     * 错误描述
     */
    private String msg;


    public R(T data, Integer code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static R ok(){
        return ok(200,null,null);
    }

    public static R ok(int code){
        return ok(code,null,null);
    }

    public static R ok(int code,String msg){
        return ok(code,null,msg);
    }

    public static <T> R ok(T obj){
        return ok(200,obj,null);
    }

    public static <T> R ok(int code,T obj,String msg){
        return new R(obj,code,msg);
    }
}
